
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>百度离线版2.0 DEMO</title>
		
		  <script type="text/javascript" src="offlinemap/map_load.js"></script>
		  <link rel="stylesheet" type="text/css" href="offlinemap/css/map.css"/>
		  <script type="text/javascript" src="offlinemap_demo/jquery.js"></script>
		  <script type="text/javascript" src="offlinemap_demo/layer/layer.js"></script>

		
		
	</head>
	<body>
		<div style="width:520px;height:340px;border:1px solid gray" id="container"></div>
		
		<input id="position" value="" type="text"/>
	</body>
</html>



<script type="text/javascript">
	
//百度坐标转高德（传入经度、纬度）
function bd_decrypt(bd_lng, bd_lat) {
    var X_PI = Math.PI * 3000.0 / 180.0;
    var x = bd_lng - 0.0065;
    var y = bd_lat - 0.006;
    var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * X_PI);
    var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * X_PI);
    var gg_lng = z * Math.cos(theta);
    var gg_lat = z * Math.sin(theta);
    return {lng: gg_lng, lat: gg_lat}
}
//高德坐标转百度（传入经度、纬度）
function bd_encrypt(gg_lng, gg_lat) {
    var X_PI = Math.PI * 3000.0 / 180.0;
    var x = gg_lng, y = gg_lat;
    var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * X_PI);
    var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * X_PI);
    var bd_lng = z * Math.cos(theta) + 0.0065;
    var bd_lat = z * Math.sin(theta) + 0.006;
    return {
        bd_lat: bd_lat,
        bd_lng: bd_lng
    };
}

   
	//点连接线
   
   
	// 百度地图API功能
	/*var map = new BMap.Map("container",{mapType: BMAP_NORMAL_MAP,minZoom:8,maxZoom:15});      //设置卫星图为底图
	var point = new BMap.Point(106.514033,29.543256);    // 创建点坐标
	map.centerAndZoom(point, 13);
	
	//var pointA = new BMap.Point(106.486654,29.490295);  // 创建点坐标A--大渡口区
	//var pointB = new BMap.Point(106.581515,29.615467);  // 创建点坐标B--江北区
	
	var x=[];
	var cc=["106.514033,29.543256","106.514572,29.542471","106.515362,29.542502","106.515776,29.541528","106.516818,29.541418","106.516872,29.540853"];
	for(var i=0;i<cc.length;i++){
		var xx=cc[i].split(",")
		//高德点转换百度点
		var bdz=bd_encrypt(xx[0],xx[1]);
		var pointB = new BMap.Point(bdz.bd_lng,bdz.bd_lat);  // 创建点坐标B--江北区
		x.push(pointB);
	}
	
	
	var pointc = new BMap.Point(106.450353,29.54713);  // 创建点坐标B--江北区
	//alert('从大渡口区到江北区的距离是：'+(map.getDistance(pointA,pointB)).toFixed(2)+' 米。');  //获取两点距离,保留小数点后两位
	var polyline = new BMap.Polyline(x, {strokeColor:"blue", strokeWeight:6, strokeOpacity:0.5});  //定义折线
	
	map.addOverlay(polyline);     //添加折线到地图上
	*/
	
	
	
	
	//添加图层
	var map = new BMap.Map("container",{mapType: BMAP_NORMAL_MAP});      //设置卫星图为底图
	var point = new BMap.Point(106.514033,29.543256);    // 创建点坐标
	var marker = new BMap.Marker(point);  // 创建标注
	map.addOverlay(marker);              // 将标注添加到地图中
	map.centerAndZoom(point, 15);
	
	var opts = {
	  width : 200,     // 信息窗口宽度
	  height: 100,     // 信息窗口高度
	  title : "海底捞王府井店" , // 信息窗口标题
	  enableMessage:true,//设置允许信息窗发送短息
	  message:"亲耐滴，晚上一起吃个饭吧？戳下面的链接看下地址喔~"
	}
	
	var infoWindow = new BMap.InfoWindow("地址：北京市东城区王府井大街88号乐天银泰百货八层", opts);  // 创建信息窗口对象 

		
	marker.addEventListener("click", function(){          
	   this.openInfoWindow(infoWindow);
	 
	});

	
	//添加折线到地图上
	
	//var pointA = new BMap.Point(106.486654,29.490295);  // 创建点坐标A--大渡口区
	//var pointB = new BMap.Point(106.581515,29.615467);  // 创建点坐标B--江北区
	
	var x=[];
	var cc=["106.514033,29.543256","106.514572,29.542471","106.515362,29.542502","106.515776,29.541528","106.516818,29.541418","106.516872,29.540853"];
	for(var i=0;i<cc.length;i++){
		var xx=cc[i].split(",")
		//高德点转换百度点
		var bdz=bd_encrypt(xx[0],xx[1]);
		var pointB = new BMap.Point(bdz.bd_lng,bdz.bd_lat);  // 创建点坐标B--江北区
		x.push(pointB);
	}
	
	
	var pointc = new BMap.Point(106.450353,29.54713);  // 创建点坐标B--江北区
	//alert('从大渡口区到江北区的距离是：'+(map.getDistance(pointA,pointB)).toFixed(2)+' 米。');  //获取两点距离,保留小数点后两位
	var polyline = new BMap.Polyline(x, {strokeColor:"blue", strokeWeight:6, strokeOpacity:0.5});  //定义折线
	
	map.addOverlay(polyline);     //添加折线到地图上
	
	
	
	

	
	
	//滚轮事件
	var scrollFunc=function(e){
		 e=e || window.event;
		 var t1=document.getElementById("position");
			 t1.value=map.getZoom();
	 }
	 /*注册事件*/
	 if(document.addEventListener){
		 document.addEventListener('DOMMouseScroll',scrollFunc,false);
	 }//W3C
	 window.onmousewheel=document.onmousewheel=scrollFunc;//IE/Opera/Chrome
		
</script>
